﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GMS.Dinasty.BO;
using GMS.Dinasty.DAL;
using System.Collections;
using GMS.MainClasses;


namespace GMS.BasicControls
{
    public partial class CustomerSpecifications : BackGroundControl
    {
        public CustomerSpecifications()
        {
            InitializeComponent();
        }

        public void SpecificationsLoad()
        {

            listBox1.Items.Clear();
            foreach (Specification specification in _specifications)
            {
                listBox1.Items.Add(specification);
            }
        }
        
        private int _idDistributor;
        public int IdDistributor
        {
            get { return _idDistributor; }
            set { _idDistributor = value; }
        }
        private int _idCustomer;
        public int IdCustomer
        {
            get { return _idCustomer; }
            set { _idCustomer = value; }
        }
        private List<User> _officers;
        public List<User> Officers
        {
            get { return _officers; }
            set { _officers = value; }
        }
        private List<Specification> _specifications;
        public List<Specification> Specifications
        {
            get { return _specifications; }
            set { _specifications = value; }
        }
        public DateTime DateStart
        {
            get { return dateStartDateTimePicker.Value; }
            set { dateStartDateTimePicker.Value = value; }
        }
        public DateTime DateEnd
        {
            get { return dateEndDateTimePicker.Value; }
            set { dateEndDateTimePicker.Value = value; }
        }
        public int DeletedSpecifications
        {
            get 
            {
                if(deletedSpecificationcheckBox.Checked == true)
                    return 1;
                else
                    return -1;
            }
            set
            {
                if (value == 1)
                    deletedSpecificationcheckBox.Checked = true;
                else
                    deletedSpecificationcheckBox.Checked = false;
            }
        }
        private void addSpecificationlinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (_officers.Count > 1)
                MessageBox.Show("Вы не можете создавать спецификацию от нескольких пользователей!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                DataAccessSpecifications DAS = new DataAccessSpecifications();
                Specification specification = DAS.InsertSpecifications((this.ParentForm as ChildForms).ConnectionString, (this.ParentForm as ChildForms).StoredProcedures[13], _idDistributor, _officers[0].IdUser, _idCustomer, dateBilldateTimePicker1.Value);
                if (specification != null)
                {
                    listBox1.Items.Add(specification);
                    listBox1.SelectedItem = specification;
                }
            }
        }

        private void deleteSpecificationLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (MessageBox.Show("Вы хотите удалить спецификацию?", "Вопрос.",  MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                DataAccessSpecifications DAS = new DataAccessSpecifications();
                if (DAS.DeleteSpecifications((this.ParentForm as ChildForms).ConnectionString, (this.ParentForm as ChildForms).StoredProcedures[14], (listBox1.SelectedItem as Specification).IdSpecifications))
                    listBox1.Items.Remove(listBox1.SelectedItem);
            }
        }


    }
}
